import 'package:flutter/material.dart';
import 'post.dart';

class CartDemo extends StatefulWidget {
  CartDemo({Key key}) : super(key: key);

  _CartDemoState createState() => _CartDemoState();
}

class _CartDemoState extends State<CartDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('CartDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        // posts.map 就是动态数据的遍历
        child: ListView(
          children: posts.map((post) {
            return GestureDetector(
              onTap: () {
                print("hia");
              },
              //发生双击时间后回调
              onDoubleTap: () {
                print("hia hia");
              },
              //      长按事件
              onLongPress: () {
                print("hia hia hia........");
              },
              // 默认有阴影和圆角，而使用container 只是个容器，没有默认效果
              child: Card(
                // shape: RoundedRectangleBorder(),
                child: Column(
                  children: <Widget>[
                    AspectRatio(
                      aspectRatio: 16 / 9,
                      // 给子元素进行圆角裁切
                      child: ClipRRect(
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(4.0),
                          topRight: Radius.circular(4.0),
                        ),
                        child: Image.network(
                          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1565600849&di=d9f34c8da5d0d53c2c5d8a4867598958&imgtype=jpg&er=1&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F30%2F20150830095308_UAQEi.thumb.700_0.jpeg',
                          fit: BoxFit.cover,
                        ),
                      ),
                      // 图片没有剪切
                      // child: Image.network(
                      //   post.imageUrl,
                      //   fit: BoxFit.cover,
                      // ),
                    ),
                    ListTile(
                      leading: CircleAvatar(
                        // backgroundImage: ,
                        backgroundImage: NetworkImage(post.imageUrl),
                      ),

                      // isThreeLine: true,
                      title: Text(post.title),
                      subtitle: Text(post.author +
                          'sdgjjkd sggggg ggggg ggggg ggg gg gggg'),
                    ),
                    Container(
                      padding: EdgeInsets.all(16.0),
                      child: Text(
                        post.description,
                        maxLines: 3,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                  ],
                ),
              ),
            );
          }).toList(),
        ),
      ),
    );
  }
}
